﻿ #define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int maxProfit(vector<int>& prices)
    {
        int ret = 0; // 记录最终结果
        for (int i = 0, prevMin = INT_MAX; i < prices.size(); i++)
        {
            ret = max(ret, prices[i] - prevMin); // 先更新结果
            prevMin = min(prevMin, prices[i]); // 再更新最⼩值
        }
        return ret;
    }
};